package com.jingogo.controller;

import com.jingogo.common.Result;
import com.jingogo.service.InvoiceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@Slf4j
@RestController
@RequestMapping("/invoice")
@Tag(name = "发票管理", description = "发票相关接口")
public class InvoiceController {

    @Autowired
    private InvoiceService invoiceService;

    @PostMapping("/add")
    @Operation(summary = "录入发票信息", description = "用户录入发票信息")
    @PreAuthorize("hasRole('USER')")
    public Result<String> addInvoice(@RequestParam @NotNull(message = "用户ID不能为空") Long userId,
                                     @RequestParam @NotNull(message = "发票信息不能为空") String invoiceInfo) {
        invoiceService.addInvoice(userId, invoiceInfo);
        return Result.success("发票信息录入成功");
    }

    @GetMapping("/get")
    @Operation(summary = "查询发票信息", description = "用户查询发票信息")
    @PreAuthorize("hasRole('USER')")
    public Result<String> getInvoice(@RequestParam @NotNull(message = "用户ID不能为空") Long userId) {
        String invoice = invoiceService.getInvoice(userId);
        return Result.success(invoice);
    }
}